package com.hzw.service;

import com.hzw.api.IAdminService;
import com.hzw.common.DateUtils;
import com.hzw.dao.AdminDao;
import com.hzw.entity.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class AdminService implements IAdminService {
    @Autowired
    AdminDao adminDao;

    @Override
    public List<Admin> selectAll(Admin admin) {
        return adminDao.select(admin);
    }

    @Override
    public Admin selectById(Admin admin) {
        return adminDao.selectById(admin.getId());
    }

    @Override
    public void updateById(Admin admin) {
        adminDao.updateById(admin);
    }

    @Override
    public void delById(Admin admin) {
        adminDao.delById(admin);
    }

    @Override
    public String insert(Admin admin) {
        Admin resAdmin = adminDao.selectByUserName(admin.getUsername());
        if (resAdmin != null){
            return "fail";
        }
        admin.setRegisterTime(DateUtils.getNowTime());
        admin.setStatus(0);
        int res = adminDao.insert(admin);
        if(res == 0){
            return "unSuccess";
        }
        return "success";
    }
}
